package com.lotter.api.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lotter.api.service.UserAccountService;
import com.lotter.common.exception.LotterCusException;
import com.lotter.invocation.StaticDataContext;
import com.lotter.model.user.UserAccount;

/**
 * 充值
 * @author cool
 *
 */
@Controller
@RequestMapping(value="/website/recharge")
public class RechargeController extends BaseController {
	
	@Autowired
	private UserAccountService userAccountService ;
	
	/**
	 * 账户信息
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/info" ,method=RequestMethod.GET)
	public Map<String,Object> info(	@RequestParam(value ="token",required = true) String token) {
		Map<String,Object> result = new HashMap<String, Object>();
		//账户信息 最好还是从数据库中查询数据  不要从session  取得数据
		try {
			Long uid = StaticDataContext.onLineUid(token);
			UserAccount userAccount = userAccountService.selectByPrimaryKey(uid);
			result.put("amount", userAccount.getAmount());
		} catch (LotterCusException e) {
			logger.error("图片上传错误");
			return ajaxLotterServer("服务器异常,请联系管理员");
		}
		return ajaxLotterSuccess(result);
	}
	
	
	/**
	 * 充值
	 * @param request
	 * @param amount  精确到分  500  代表5元
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/insert" ,method=RequestMethod.POST)
	public Map<String,Object> insert(HttpServletRequest request,
		@RequestParam(value="amount",required = true)Long amount){
		if(amount == null || amount.longValue() <= 0 ){
			return ajaxLotterStage("充值金额有误");
		}
		Map<String , Object> paramMap = new HashMap<String , Object>();
		paramMap.put("amount",amount);
	    String orderNo = String.valueOf(System.currentTimeMillis());    // 订单编号
        paramMap.put("orderNo",orderNo); 
		
        Date orderDate = new Date();//订单日期
        String orderDateStr = new SimpleDateFormat("yyyyMMdd").format(orderDate);// 订单日期
        paramMap.put("orderDate",orderDateStr);
        
		
		
		return null ;
	}
	

}
